package hadoop.ch03.v17124080112;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class UploadHDFSFile {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        // 配置 NameNode 地址，具体根据你的NameNode IP 配置
        URI uri = new URI("hdfs://192.168.30.131:8020");
        // 指定用户名 , 获取 FileSystem 对象
        FileSystem fs = FileSystem.get(uri, conf, "hadoop");
        //local file
        Path src = new Path("e:\\test4.txt");
        //HDFS file
        Path dst = new Path("/17124080112/test4.txt");
        fs.copyFromLocalFile(src,dst);
        // 不需要再操作 FileSystem 了，关闭
        fs.close();

        System.out.println("Upload Successfully!");
    }
}
